package com.aurora.blog.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.aurora.common.log.annotation.Log;
import com.aurora.common.log.enums.BusinessType;
import com.aurora.common.security.annotation.RequiresPermissions;
import com.aurora.blog.domain.BlogComments;
import com.aurora.blog.service.IBlogCommentsService;
import com.aurora.common.core.web.controller.BaseController;
import com.aurora.common.core.web.domain.AjaxResult;
import com.aurora.common.core.utils.poi.ExcelUtil;
import com.aurora.common.core.web.page.TableDataInfo;

/**
 * 评论Controller
 * 
 * @author aurora
 * @date 2024-06-04
 */
@RestController
@RequestMapping("/blogComments")
public class BlogCommentsController extends BaseController
{
    @Autowired
    private IBlogCommentsService blogCommentsService;

    /**
     * 查询评论列表
     */
    @RequiresPermissions("blog:blogComments:list")
    @GetMapping("/list")
    public TableDataInfo list(BlogComments blogComments)
    {
        startPage();
        List<BlogComments> list = blogCommentsService.selectBlogCommentsList(blogComments);
        return getDataTable(list);
    }

    /**
     * 导出评论列表
     */
    @RequiresPermissions("blog:blogComments:export")
    @Log(title = "评论", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BlogComments blogComments)
    {
        List<BlogComments> list = blogCommentsService.selectBlogCommentsList(blogComments);
        ExcelUtil<BlogComments> util = new ExcelUtil<BlogComments>(BlogComments.class);
        util.exportExcel(response, list, "评论数据");
    }

    /**
     * 获取评论详细信息
     */
    @RequiresPermissions("blog:blogComments:query")
    @GetMapping(value = "/{commentId}")
    public AjaxResult getInfo(@PathVariable("commentId") Long commentId)
    {
        return success(blogCommentsService.selectBlogCommentsByCommentId(commentId));
    }

    /**
     * 新增评论
     */
    @RequiresPermissions("blog:blogComments:add")
    @Log(title = "评论", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BlogComments blogComments)
    {
        return toAjax(blogCommentsService.insertBlogComments(blogComments));
    }

    /**
     * 修改评论
     */
    @RequiresPermissions("blog:blogComments:edit")
    @Log(title = "评论", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BlogComments blogComments)
    {
        return toAjax(blogCommentsService.updateBlogComments(blogComments));
    }

    /**
     * 删除评论
     */
    @RequiresPermissions("blog:blogComments:remove")
    @Log(title = "评论", businessType = BusinessType.DELETE)
	@DeleteMapping("/{commentIds}")
    public AjaxResult remove(@PathVariable Long[] commentIds)
    {
        return toAjax(blogCommentsService.deleteBlogCommentsByCommentIds(commentIds));
    }
}
